package com.luanye.enjoy.vo;

import com.luanye.enjoy.enums.ResultCode;
import com.luanye.enjoy.enums.StatusCode;
import lombok.Data;

@Data
public class RespBean {

    private int code;
    private String msg;
    private Object obj;

    /**
     *  手动设置返回Bean
     * */
    public RespBean(int code, String msg, Object data){
        this.code = code;
        this.msg = msg;
        this.obj = data;
    }

    /**
     *  默认返回成功状态码，数据对象
     * */
    public RespBean(Object data){
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMsg();
        this.obj = data;
    }

    /**
     *  返回指定状态码，数据对象
     * */
    public RespBean(StatusCode statusCode, Object data){
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.obj = data;
    }
    /**
     *  只返回状态码
     * */
    public RespBean(StatusCode statusCode){
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.obj = null;
    }

    public static RespBean success() {
        return new RespBean(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), null);
    }

    public static RespBean success(Object obj) {
        return new RespBean(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), obj);
    }

    public static RespBean success(StatusCode status, Object obj) {
        return new RespBean(status.getCode(), status.getMsg(), obj);
    }

    public static RespBean error(Integer code, String message) {
        return new RespBean(code, message, null);
    }

    public static RespBean error(StatusCode status) {
        return new RespBean(status.getCode(), status.getMsg(), null);
    }

    public static RespBean error(StatusCode status, Object obj) {
        return new RespBean(status.getCode(), status.getMsg(), obj);
    }

}
